package com.hqyj.finance.server.invest.financeinvest.controller;

import com.hqyj.finance.server.invest.financeinvest.entity.UserStock;
import com.hqyj.finance.server.invest.financeinvest.json.R;
import com.hqyj.finance.server.invest.financeinvest.service.UserStockService;
import com.hqyj.finance.server.invest.financeinvest.views.UserStockKLineGraphicView;
import com.hqyj.finance.server.invest.financeinvest.views.UserStockView;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/userstock")
@RestController
public class UserStockController {

    @Resource
    private UserStockService userStockService;

    @PostMapping("/")
    public R saveUserStock(@RequestBody UserStock userStock) {
        try {
            if (userStockService.saveUserStock(userStock)) {
                return R.success("添加用户自选股资料成功！");
            }
            return R.fail("添加用户自选股资料失败！");
        } catch (Exception ex) {
            ex.printStackTrace();
            return R.error("程序出现异常！");
        }
    }

    @GetMapping("/list")
    public R queryUserStockRealList(@RequestParam("uid") Integer uid) {
        try {
            List<UserStockView> userStockViewList = userStockService.queryUserStockViewByUid(uid);
            return R.success("查询用户自选股实时行情数据成功！", userStockViewList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return R.error("程序出现异常！");
        }
    }

    @GetMapping("/kline")
    public R queryUserStockKlineGraphicViewByCodeAndType(@RequestParam("code") String code, @RequestParam("type") String type) {
        try {
            UserStockKLineGraphicView userStockKLineGraphicView = userStockService.queryUserStockLineGraphicViewByCode(code, type);
            return R.success("查询指定股票K线图数据成功！", userStockKLineGraphicView);
        } catch (Exception ex) {
            ex.printStackTrace();
            return R.error("程序出现异常！");
        }
    }
}
